<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
  <head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <!--<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />-->
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <div class="x-body">
        <form class="layui-form" th:attr="formAction=${putUrl}">
          <div class="layui-form-item">
              <input type="hidden" id="id" name="id" th:value="${clause.id}">
              <label for="clause" class="layui-form-label">
                  <span class="x-red">*</span>条款号
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="clause" name="clause" required="" lay-verify="clause" th:value="${clause.clause}"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>将会成为条款的标识
              </div>
          </div>
          <div class="layui-form-item">
              <label for="alias" class="layui-form-label">
                  <span class="x-red">*</span>条款别名
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="alias" name="alias" required="" lay-verify="alias" th:value="${#strings.isEmpty(clause.alias)||clause.alias=='null'?'':clause.alias}"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="titel" class="layui-form-label">
                  <span class="x-red">*</span>条款标题
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="titel" name="titel" required="" lay-verify="titel" th:value="${clause.titel}"
                  autocomplete="off" class="layui-input">
              </div>
              <div class="layui-form-mid layui-word-aux">
                  <span class="x-red">*</span>
              </div>
          </div>
          <div class="layui-form-item">
              <label for="lawsId" class="layui-form-label">
                  <span class="x-red">*</span>所属法规
              </label>
              <div class="layui-input-inline">
                  <select lay-search="" lay-filter="lawsId"  id="lawsId" name="lawsId">
                      <option th:each="law:${laws}" th:value="${law.id}" th:text="${law.lawsName}" th:selected="${law.id==clause.lawsId?'true':'false'}">法规4</option>
                  </select>
              </div>
              <div class="layui-form-mid layui-word-aux">
              </div>
          </div>
          <div class="layui-form-item">
              <label for="catalogId" class="layui-form-label">
                  <span class="x-red">*</span>所属目录
              </label>
              <div class="layui-input-inline">
                  <select id="catalogId" name="catalogId">
                      <option th:each="catalog:${catalogs}" th:value="${catalog.id}" th:text="${catalog.catalog}" th:selected="${catalog.id==clause.catalogId?'true':'false'}">法规4</option>
                  </select>
              </div>
          </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">条款内容</label>
                <div class="layui-input-inline">
                    <textarea id="content" name="content" placeholder="请输入内容" required="" lay-verify="content" class="layui-textarea" style="width:400px">[[${clause.content=='null'?'':clause.content}]]</textarea>
                </div>
                <div class="layui-form-mid layui-word-aux">
                    <span class="x-red">*必填</span>
                </div>
            </div>
          <div class="layui-form-item">
              <button id="modifyBtn" style="margin-left: 110px" class="layui-btn" lay-filter="modify" lay-submit="">
                  增加
              </button>
          </div>
      </form>
    </div>
    <script>
        layui.use(['form','layer'], function(){
            layer = layui.layer;//弹出层
            $ = layui.jquery;
             var form = layui.form;
              //自定义验证规则
              form.verify({
                  clause: function(value){
                  if(value.length <=0){
                    return '条款号不能为空';
                  }
                }
                ,titel: function(value){
                      if(value.length <=0){
                          return '标题不能为空';
                      }
                }
                ,content: function(value){
                      if(value.length <=0){
                          return '内容不能为空不能为空';
                      }
                  }
              });
          //监听提交
          form.on('submit(modify)', function(formData){
              console.log(formData.field)
              if(formData.field.catalog == -1){
                  layer.msg("该法规还没有目录！",{icon:5,time:1000});return false;
              }
              var action = $('form').attr("formAction");
              $.ajax({
                  type:"post",
                  url:"/"+action,
                  data:formData.field,
                  dataType:"json",
                  success:function(data){
                      console.log(data);
                      if(data.status==1){
                          layer.msg(data.info, {icon: 6,time:1000},function () {
                              var index = parent.layer.getFrameIndex(window.name);
                              parent.layer.close(index);
                          });
                          return false;
                      } else{
                          layer.msg(data.info,{icon:5,time:1000});return false;
                      }
                  },
                  error:function (err) {
                      console.log(err)
                  }
              });
            return false;
          });
          form.on('select(lawsId)', function (res) {
              $.ajax({
                  type:"post",
                  url:"/selectByLawId",
                  data:{"lid":res.value},
                  dataType:"json",
                  success:function(data){
                      console.log(data)
                      if(data.status==1){
                          var hml = "";
                          $.each(data.info,function(index,value){
                              hml += "<option value=\""+value.id+"\" class=\"\">"+value.catalog+"</option>";
                          });
                          $("#catalogId").html(hml);
                          layui.form.render('select');
                          return false;
                      } else{
                          var hml = "<option lay-value=\"-1\" class=\"\">"+data.info+"</option>";
                          $("#catalogId").html(hml);
                          layui.form.render('select');
                          return false;
                      }
                  },
                  error:function (err) {
                      console.log(err)
                  }
              });
          });
        });
    </script>
    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();</script>
  </body>

</html>